package cn.tedu.jsd2205the.back.end.project.controller;

import cn.tedu.jsd2205the.back.end.project.pojo.dto.ProductPagerDTO;
import cn.tedu.jsd2205the.back.end.project.pojo.entity.Product;
import cn.tedu.jsd2205the.back.end.project.pojo.entity.User;
import cn.tedu.jsd2205the.back.end.project.pojo.entity.ViewHistory;
import cn.tedu.jsd2205the.back.end.project.pojo.vo.ProductDetailVO;
import cn.tedu.jsd2205the.back.end.project.pojo.vo.ProductSimpleVO;
import cn.tedu.jsd2205the.back.end.project.restful.JsonResult;
import cn.tedu.jsd2205the.back.end.project.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@Api(tags = "商品模块")
@RequestMapping( "/product")
public class ProductController {

    @Autowired
    private IProductService service;

    /**
     * 查询最新上架的商品
     * @return
     */
    @GetMapping("/selectNew")
    @ApiOperation("查询最新上架的3个商品")
    public List<ProductSimpleVO> selectNew() {
        return service.selectNew();
    }

    /**
     * 分页查询商品
     * @param productPagerDTO
     * @return
     */
    @ApiOperation("分页查询全部商品")
    @GetMapping("/selectByPage")
    public Map<String, Object> selectByPage(ProductPagerDTO productPagerDTO) {
        System.out.println(productPagerDTO);
        List<Product> products = service.selectByPage(productPagerDTO);
        int total = service.selectCountByPage(productPagerDTO);

        return JsonResult.returnResultMap(total, products);
    }

}
